package com.hs.sfzy.controller;

import com.github.pagehelper.PageInfo;
import com.hs.sfzy.entity.Course;
import com.hs.sfzy.service.CourseService;
import com.hs.sfzy.until.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName CourseController
 * @Description TODO
 * @Author Chen
 * @Date 2025年08月12日 21:10
 * @Version 1.0
 */
@RestController
@RequestMapping("course")
public class CourseController {
    @Autowired
    private CourseService courseService;

    @GetMapping("{id}")
    public R getCourseByCourseId(@PathVariable("id") Integer id) {
        Course courseById = courseService.getCourseByCourseId(id);
        return R.ok(courseById);
    }

    @GetMapping("/list")
    public R getCourseList(Course course,
                           @RequestParam(required = false, defaultValue = "1") Integer pageNum,
                           @RequestParam(required = false, defaultValue = "7") Integer pageSize) {
        PageInfo<Course> courseList = courseService.getCourseList(course, pageNum, pageSize);
        System.out.println("course是" + course);
        return R.ok(courseList);
    }
    @GetMapping("conid")
    public R getCourseConId(Integer id,
                            @RequestParam(required = false, defaultValue = "1") Integer pageNum,
                            @RequestParam(required = false, defaultValue = "3") Integer pageSize) {
        PageInfo<Course> courseByzxsId = courseService.getCourseByzxsId(id, pageNum, pageSize);
        return R.ok(courseByzxsId);

    }

    @GetMapping("sort")
    public R selectCourseBySort(String sortType,String interval,@RequestParam(required = false,defaultValue = "1") int pageNum,@RequestParam(required = false,defaultValue = "5") int pageSize){
        System.out.println(sortType+"111");
        PageInfo<Course> coursePageInfo = courseService.selectCourseBySort(sortType, interval, pageNum, pageSize);
        return R.ok(coursePageInfo);
    }
}
